package com.guanyong.admin.controllers.api;

import com.guanyong.admin.handle.UserHandle;
import com.guanyong.model.FuncModel;
import com.guanyong.model.RoleModel;
import com.guanyong.model.UserBaseModel;
import com.guanyong.services.FuncService;
import com.guanyong.services.MerchantService;
import com.guanyong.services.RoleService;
import com.guanyong.utils.Comm.DateExt;
import com.guanyong.utils.Comm.ResultCode;
import com.guanyong.utils.Comm.ResultObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

/**
 * Created by mxk on 2017/6/7.
 */
@RestController
@RequestMapping("/api/merchant/")
public class MerchantApi {
    @Autowired
    MerchantService merchantService;



    @RequestMapping(value = "getmerchantlist", method = RequestMethod.GET)
    ResultObject<HashMap<String,Object>> getmerchantlist(HttpServletRequest request,
                                                     @RequestParam String name,
                                                     @RequestParam int pno,
                                                     @RequestParam int pagesize,
                                                     @RequestParam int allcount) {
        ResultObject<HashMap<String,Object>> result = new ResultObject<HashMap<String,Object>>();
        HashMap<String,Object> hashMap=
                merchantService.GetMerchantModelList(name,pno, pagesize,allcount);
        result.setResult(hashMap);
        return result;
    }


    @RequestMapping(value = "getmerchantloglist", method = RequestMethod.GET)
    ResultObject<HashMap<String,Object>> getmerchantloglist(HttpServletRequest request,
                                                         @RequestParam String ak,
                                                            @RequestParam String year,
                                                            @RequestParam String moth,
                                                            @RequestParam String name,
                                                         @RequestParam int pno,
                                                         @RequestParam int pagesize,
                                                         @RequestParam int allcount) {
        ResultObject<HashMap<String,Object>> result = new ResultObject<HashMap<String,Object>>();


        HashMap<String,Object> hashMap=
                merchantService.GetMerchantLogModelList(ak,year,moth,name,pno, pagesize,allcount);
        result.setResult(hashMap);
        return result;
    }


    @RequestMapping(value = "getmerchantlogallcount", method = RequestMethod.GET)
    ResultObject< List<HashMap<String,Integer>> > getmerchantlogallcount(HttpServletRequest request,
                                                            @RequestParam String ak,
                                                            @RequestParam String year,
                                                            @RequestParam String moth,
                                                            @RequestParam String name) {
        ResultObject< List<HashMap<String,Integer>> > result = new ResultObject< List<HashMap<String,Integer>> >();
        List<HashMap<String,Integer>>  hashMap= merchantService.GetAllCountLog(ak,year,moth,name);
        result.setResult(hashMap);
        return result;
    }

    @RequestMapping(value = "getctbyyear", method = RequestMethod.GET)
    ResultObject< List<HashMap<Integer,Integer>>>  getCountByYear(HttpServletRequest request,
      @RequestParam String akid)
                                                                      {
        ResultObject<List<HashMap<Integer,Integer>>> result =
                new ResultObject<List<HashMap<Integer,Integer>>>();
        List<HashMap<Integer,Integer>> hashMap= merchantService.GetCountByYear(akid);
        result.setResult(hashMap);
        return result;
    }


    @RequestMapping(value = "getctbyfilm", method = RequestMethod.GET)
    ResultObject< List<HashMap<String,Integer>>>  getCountByfilm(HttpServletRequest request,
                                                                  @RequestParam String akid)
    {
        ResultObject<List<HashMap<String,Integer>>> result =
                new ResultObject<List<HashMap<String,Integer>>>();
        List<HashMap<String,Integer>> hashMap= merchantService.GetCountByFilmName(akid);
        result.setResult(hashMap);
        return result;
    }

    @RequestMapping(value = "getctbyhtime", method = RequestMethod.GET)
    ResultObject< List<HashMap<String,Integer>>>  getCountByfilm(HttpServletRequest request,
                                                                 @RequestParam String akid,
                                                                 @RequestParam String date)
    {
        ResultObject<List<HashMap<String,Integer>>> result =
                new ResultObject<List<HashMap<String,Integer>>>();
        String btime=date+" 00:00:00:000";
        String etime=date+" 23:59:59:999";
        List<HashMap<String,Integer>> hashMap= merchantService.GetCountByTimeH(akid,btime,etime);
        result.setResult(hashMap);
        return result;
    }
}


